home *** CD-ROM | disk | FTP | other *** search
- /* gennums.c generate number tables for stringart */
-
- #include <stdio.h> /* standard I/O */
- #include <fmath.h> /* floating point math */
-
- /*
- This demo creates random vector designs. This is accomplished by
- randomly choosing a function for each coordinate halve of the two
- points describing a vector that moves through two dimensional
- space. Both x coordinate halves cannot be the same since the design
- would simply be a collection of vertical lines. Similarly both
- y coordinate halves cannot be the same.
-
- The functions are:
-
- function[0][x] = sin( 2*PI*x/NUMLINES )
- function[1][x] = -sin( 2*PI*x/NUMLINES )
- function[2][x] = cos( 2*PI*x/NUMLINES )
- function[3][x] = -cos( 2*PI*x/NUMLINES )
- function[4][x] = sin( 4*PI*x/NUMLINES )
- function[5][x] = -sin( 4*PI*x/NUMLINES )
- function[6][x] = cos( 4*PI*x/NUMLINES )
- function[7][x] = -cos( 4*PI*x/NUMLINES )
- function[8][x] = sin( 6*PI*x/NUMLINES )
- function[9][x] = -sin( 6*PI*x/NUMLINES )
- function[10][x] = cos( 6*PI*x/NUMLINES )
- function[11][x] = -cos( 6*PI*x/NUMLINES )
- function[12][x] = 2 * abs( x - (NUMLINES/2) - 1 )
-
- The values of the functions were pre computed to have the demo
- run as fast as possible. The program will only terminate on
- interrupt since it is in an endless loop.
- */
-
- /* these should be in a common header file, but I'm lazy */
- #define NUMLINES 343 /* number of vectors in a design */
- #define NUM_FUNCTIONS 12 /* number of functions */
-
- int p [NUMLINES];
-
- main()
- {
- int i, j, k, l, m;
- FILE *f;
-
- f = fopen ("stringnums.c", "w");
- fprintf (f, "\n\t/* This source file generated by gennums.c */\n\n\n");
- fprintf (f, "#define NUM_FUNCTIONS %d\n", NUM_FUNCTIONS);
- fprintf (f, "#define NUMLINES %d\n\n", NUMLINES);
- fprintf (f, "int p [NUM_FUNCTIONS][NUMLINES] = {\n\n");
- for (i = 0; i < NUM_FUNCTIONS; i++) {
- cifer (i, 1024);
- /* scaling down is faster with a power of 2 */
- dumparray (f, i);
- }
- fprintf (f, "\t}\n};\n\n");
- fclose (f);
- }
-
- dumparray (f, n) FILE *f; int n;
- {
- int i;
-
- if (n != 0)
- fprintf (f, "\t},\n\n");
- fprintf (f, "\t{\n");
- for (i = 0; i < NUMLINES; i++) {
- fprintf (f, "\t%d", p[i]);
- if (i != NUMLINES - 1)
- fprintf (f, ",");
- if (i % 7 == 6)
- fprintf (f, "\n");
- }
- }
-
-
- #define PI 3.1415927
-
- int
- cifer (func, scale) int func, scale; /* Hey Uncle Jed... */
- {
- float tmp;
- int x;
-
- for (x = 0; x < NUMLINES; x++) {
- /* clumsy, but doesn't need to be efficient */
- switch (func) {
- case 0:
- tmp = sin( 2*PI*x/NUMLINES);
- break;
- case 1:
- tmp = -sin( 2*PI*x/NUMLINES);
- break;
- case 2:
- tmp = cos( 2*PI*x/NUMLINES);
- break;
- case 3:
- tmp = -cos( 2*PI*x/NUMLINES);
- break;
- case 4:
- tmp = sin( 4*PI*x/NUMLINES);
- break;
- case 5:
- tmp = -sin( 4*PI*x/NUMLINES);
- break;
- case 6:
- tmp = cos( 4*PI*x/NUMLINES);
- break;
- case 7:
- tmp = -cos( 4*PI*x/NUMLINES);
- break;
- case 8:
- tmp = sin( 6*PI*x/NUMLINES);
- break;
- case 9:
- tmp = -sin( 6*PI*x/NUMLINES);
- break;
- case 10:
- tmp = cos( 6*PI*x/NUMLINES);
- break;
- case 11:
- tmp = -cos( 6*PI*x/NUMLINES);
- break;
- case 12:
- tmp = 2 * abs( x - (NUMLINES/2) - 1); /* not used */
- break;
- default:
- tmp = x; /* shouldn't happen */
- break;
- }
- p [x] = (int)(tmp * scale);
- }
- }
-
-
-
-